package cn.net.xyan.pay.core.support

import org.hibernate.boot.model.naming.Identifier
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy

/**
 * Created by zarra on 17/4/14.
 */

class CorePhysicalNamingStrategy: SpringPhysicalNamingStrategy() {
    override fun toPhysicalColumnName(name: Identifier?, jdbcEnvironment: JdbcEnvironment?): Identifier {
        val raw =  super.toPhysicalColumnName(name, jdbcEnvironment)
        return getIdentifier("c_"+raw.text,raw.isQuoted,jdbcEnvironment)
    }

    override fun toPhysicalTableName(name: Identifier?, jdbcEnvironment: JdbcEnvironment?): Identifier {
        val raw = super.toPhysicalTableName(name, jdbcEnvironment)
        return getIdentifier("t_"+raw.text,raw.isQuoted,jdbcEnvironment)
    }

    override fun toPhysicalSchemaName(name: Identifier?, jdbcEnvironment: JdbcEnvironment?): Identifier? {
        val raw = super.toPhysicalSchemaName(name, jdbcEnvironment)
        return raw
        //return getIdentifier(""+raw.text,raw.isQuoted,jdbcEnvironment)
    }

    override fun toPhysicalCatalogName(name: Identifier?, jdbcEnvironment: JdbcEnvironment?): Identifier? {
        val raw = super.toPhysicalCatalogName(name, jdbcEnvironment)
        return raw
        //return getIdentifier(""+raw.text,raw.isQuoted,jdbcEnvironment)
    }

    override fun toPhysicalSequenceName(name: Identifier?, jdbcEnvironment: JdbcEnvironment?): Identifier? {
        val raw = super.toPhysicalSequenceName(name, jdbcEnvironment)
        return raw
        //return getIdentifier(""+raw.text,raw.isQuoted,jdbcEnvironment)
    }
}